<?php
namespace Home\Controller;

use Think\Controller;
use Home\Model\Webchat;

class BaseController extends Controller
{
	private $user = null;
	private $exceptAuth = [
		'Site' => ['login'], 
	];

	public function __construct() {
		parent::__construct();

		if (isset($_GET['signature']) && ACTION_NAME == 'index') {
    		(new Webchat())->process();
    		exit();
    	}

		$this->handleSession();
		if ($this->user === null && 
			!in_array(ACTION_NAME, $this->exceptAuth[CONTROLLER_NAME])) {
			redirect(U('site/login'), 2, '请先登陆...');
		} else {
			$this->assign('user', $this->user);
		}

	}

	protected function handleSession() {
		if (session('uid')) {
			$user = M("User");
			$userArray = $user->where('status=1 and id='.session('uid'))->select(); 

			$this->user = $userArray[0];
		}
	}
}